<template>
	<view style="height: 100vh;background-color: #F5F7FA;">
		<hx-navbar ref="hxnb" :config="config" />
		<view class="view-body">
			<custom-image label="火车票"></custom-image>
			<custom-input label="姓名" value="张三" :required="true"></custom-input>
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-left">
						乘车时间
					</view>
					<view class="uni-list-cell-db">
						<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
							<view class="text" style="text-align:right">{{date}}
								<uni-icons type="right" size="18" color="#1224534d" class="ml-8"></uni-icons>
							</view>
						</picker>
					</view>
				</view>
			</view>
			<custom-input label="票价" value="22.00" :required="true"></custom-input>
			<custom-input label="进项税额" value="1.20" :required="true"></custom-input>
			<custom-input label="火车票号" value="E042391" :required="true" :readonly="true"></custom-input>
			<custom-input label="车次" value="G952" :required="true" :readonly="true"></custom-input>
			<custom-picker label="席别" :change="bindPickerChange1" :index="index1" :array="array1"></custom-picker>
			<custom-picker label="出发站" :change="bindPickerChange" :index="index" :array="array"></custom-picker>
			<custom-picker label="到达站" :change="bindPickerChange2" :index="index2" :array="array2"></custom-picker>
		</view>
		<view class="view-footer">
			<custom-save-button :click="click"></custom-save-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				title: 'picker',
				array1: ['二等座', '特等座', '一等座', '无座'],
				index1: 0,
				array: ['长春西', '北京西', '上海', '深圳'],
				index: 0,
				array2: ['北京西', '长春西', '上海', '深圳'],
				index2: 0,
				date: currentDate,
				time: '12:01',
				content: [{
					iconPath: '/static/font/iconfont.css',
					selectedIconPath: '/static/font/iconfont.css',
					active: false
				}, ],
				config: {
					title: '火车票',
					color: '#FFFFFF',
					//背景颜色;参数一：透明度（0-1）;参数二：背景颜色（array则为线性渐变，string为单色背景）
					backgroundColor: [1, ['#0060FF', '#0052D9']],
					// 滑动屏幕后切换颜色，注意颜色为数组时长度必须一样，还有使用滑动切换必须监听 onPageScroll 事件
					slideBackgroundColor: [0.2, ['#0060FF', '#0052D9']],
					// 状态栏 ，数组则为滑动变色
					statusBarBackground: ['', '#ffffff'],
					backgroundColorLinearDeg: '229deg'
				},
			}
		},
		onPageScroll(e) {
			// 重点，用到滑动切换必须加上
			this.$refs.hxnb.pageScroll(e);
		},
		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			bindPickerChange1: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index1 = e.detail.value
			},
			bindPickerChange2: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index2 = e.detail.value
			},
			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			bindTimeChange: function(e) {
				this.time = e.detail.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			bindPickerChange: function(e) {
				this.index = e.detail.value;
			},
			click() {
				uni.navigateTo({
					url: '/pages/train/view/view'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-list {
		height: 48px;
		background: #FFFFFF;
		margin-top: 8px;
		margin-bottom: 8px;
		position: relative;
		width: 100%;
		display: flex;
		flex-direction: column;

		.uni-list-cell {
			position: relative;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;

			.uni-list-cell-left {
				font-size: 16px;
				color: #12245380;
				padding: 0px 0px 0px 11px;
				line-height: 48px;
			}

			.uni-list-cell-db {
				flex: 1;

				.text {
					text-align: right;
					font-size: 16px;
					color: #122453;
					line-height: 48px;
					padding: 0px 18.5px 0px 0px;
				}

				.ml-8 {
					margin-left: 8px;
				}
			}
		}
	}

	.view-body {
		padding-bottom: 48px;
	}

	.view-footer {
		height: 48px;
		position: fixed;
		bottom: 0;
		width: 100%;
	}
</style>
